// 抽象类
// Created by FanGccU on 2025/6/14.
//

#include <iostream>
using namespace std;

/**
 * 形状
 * 抽象类
 */
class Shape {
protected:
    int width;
    int height;

public:
    void setWidth(const int w) {
        width = w;
    }

    void setHeight(const int h) {
        height = h;
    }

    // 声明抽象函数，有抽象函数的类一定是抽象类
    virtual int getArea() = 0;
};

/**
 * 派生类
 * 正方形
 */
class Rectangle : public Shape {
public:
    // 派生类实现抽象函数
    int getArea() override {
        return width * height;
    }
};

/**
 * 派生类
 * 三角形
 */
class Triangle : public Shape {
public:
    int getArea() override {
        return (width * height) / 2;
    }
};

int main(int argc, char *argv[]) {
    Rectangle rect;
    rect.setWidth(5);
    rect.setHeight(7);
    cout << "正方形的面积为：" << rect.getArea() << endl;

    Triangle tri;
    tri.setWidth(5);
    tri.setHeight(7);
    cout << "三角形的面积为：" << tri.getArea() << endl;
}
